package com.ruoyi.web.controller.prevention;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.PreventionHiddenInfoRecord;
import com.ruoyi.system.service.PreventionHiddenInfoRecordService;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 巡检_排查_隐患表(PreventionHiddenInfoRecord)表控制层
 * @author makejava
 * @since 2023-03-22 10:06:39
 */
@RestController
@RequestMapping("/preventionHiddenInfoRecord")
public class PreventionHiddenInfoRecordController extends BaseController {

    @Resource
    private PreventionHiddenInfoRecordService preventionHiddenInfoRecordService;

    /**
     * 分页查询
     * @param preventionHiddenInfoRecord 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(PreventionHiddenInfoRecord preventionHiddenInfoRecord) {
        startPage();
        List<PreventionHiddenInfoRecord> preventionHiddenInfoRecordList = this.preventionHiddenInfoRecordService.queryByPage(preventionHiddenInfoRecord);
        return getDataTable(preventionHiddenInfoRecordList);
    }

    /**
     * 通过主键查询单条数据
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Integer id) {
        return AjaxResult.success(this.preventionHiddenInfoRecordService.queryById(id));
    }

    /**
     * 新增数据
     * @param preventionHiddenInfoRecord 实体
     * @return 新增结果
     */
    @PostMapping("/create")
    public AjaxResult add(@RequestBody PreventionHiddenInfoRecord preventionHiddenInfoRecord) {
        return AjaxResult.success(this.preventionHiddenInfoRecordService.insert(preventionHiddenInfoRecord));
    }

    /**
     * 编辑数据
     * @param preventionHiddenInfoRecord 实体
     * @return 编辑结果
     */
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody PreventionHiddenInfoRecord preventionHiddenInfoRecord) {
        return AjaxResult.success(this.preventionHiddenInfoRecordService.update(preventionHiddenInfoRecord));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("/delete")
    public AjaxResult deleteById(Integer id) {
        return AjaxResult.success(this.preventionHiddenInfoRecordService.deleteById(id));
    }

    /**
     * 统计_巡检任务隐患数
     * @return 单条数据
     */
    @PostMapping("/countHidden")
    public AjaxResult countHidden(Integer taskId) {
        return AjaxResult.success(this.preventionHiddenInfoRecordService.countHidden(taskId));
    }


}

